package com.hippo.core.ui.components

import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.hippo.core.R

@Composable
fun ManuLeft(modifier: Modifier = Modifier,onPress: () -> Unit,onTap: () -> Unit) {

    var isPressed by remember { mutableStateOf(false) }
    var pressTime by remember { mutableStateOf(0L) }

    Box(
        modifier = modifier.size(120.dp, 180.dp)
    ) {


        StateImage(
            modifier = Modifier
                .align(Alignment.CenterStart)
                .size(120.dp, 180.dp),
            checkedImageRes = R.mipmap.left_bs,
            defaultImageRes = R.mipmap.left_bn,
            checked = isPressed
        )

        Image(
            painter = painterResource(id = if (isPressed)  R.mipmap.left_an else R.mipmap.left_as),
            contentDescription = null,
            modifier = modifier
                .align(Alignment.CenterEnd)
                .padding(30.dp)
                .size(40.dp)
                .pointerInput(Unit) {
                    detectTapGestures(
                        onPress = {
                            val currentTime = System.currentTimeMillis()
                            if (currentTime - pressTime > 600) {
                                isPressed = true
                                onPress()
                            } else {
                                Log.i("sss", "ManuTop: 重复点击")
                            }
                            pressTime = currentTime
                        },
                        onTap = {
                            isPressed = false
                            onTap()
                        }
                    )

                }

        )
    }

}